﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using Tanmia.Basis.Domain;
using Tanmia.NHibernate;

namespace Tanmia.Domain
{
    public class PersonDomain : BaseDomainObject<Person>
    {
        public PersonRepository PersonRep
        {
            get { return repository as PersonRepository; }
        }

        public PersonDomain()
        {
            repository = new PersonRepository();
        }

        public IList<Person> GetsByItemColor(Item item, Color color)
        {
            IList<Person> retVal = PersonRep.Gets(item, color);
            retVal.Insert(0, Person.SelectManufacturer);
            return retVal;
        }

        public IList<Person> GetsByType(PersonTypeEnum personType)
        {
            switch (personType)
            {
                case PersonTypeEnum.Customer:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.SelectCustomer);
                case PersonTypeEnum.Manufacturer:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.SelectManufacturer);
                case PersonTypeEnum.Merchant:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.SelectMerchant);
            }

            return null;
        }

        public IList<Person> GetsByTypeWithEasyAdd(PersonTypeEnum personType)
        {
            switch (personType)
            {
                case PersonTypeEnum.Customer:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.EasyAdd, Person.SelectCustomer);
                case PersonTypeEnum.Manufacturer:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.EasyAdd, Person.SelectManufacturer);
                case PersonTypeEnum.Merchant:
                    return GetsWithSelect(repository.Gets(x => x.PersonType == personType), Person.EasyAdd, Person.SelectMerchant);
            }

            return null;
        }

    }
}
